Skip to content

[storage] use node:stream/consumers in samples and snippets#38850

Draft
jeremymeng wants to merge 1 commit into
mainfrom
jeremymeng/storage-samples-stream-consumers
Draft

[storage] use node:stream/consumers in samples and snippets#38850
jeremymeng wants to merge 1 commit into
mainfrom
jeremymeng/storage-samples-stream-consumers

Conversation

@jeremymeng
Copy link
Copy Markdown
Member

Packages impacted by this PR

  • @azure/storage-blob
  • @azure/storage-file-datalake
  • @azure/storage-file-share

Issues associated with this PR

N/A

Describe the problem that is addressed by this PR

The Node.js samples and README/TSDoc snippets under sdk/storage/storage-* each shipped a hand-rolled streamToBuffer / streamToString helper that wires up data/end/error handlers on the readable stream. Node.js has had a built-in node:stream/consumers module for this since 16.7, so the helper is unnecessary noise that obscures the actual sample logic and gives readers an outdated impression of best practice.

What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen?

The samples now use buffer() from node:stream/consumers to read the full payload as a Node Buffer. buffer() was chosen over text() because:

  • It returns raw bytes, which is the more general primitive. Readers see how to download a blob/file as bytes (useful for binary content) and can call .toString() for text.
  • A short inline comment alongside the call points to text() from the same module as the one-liner alternative when only a string is needed.

Other node:stream/consumers exports (arrayBuffer(), blob(), json()) are mentioned implicitly by linking readers to the module — we didn't want to weigh down each sample with every variation.

Affected source files (the samples-dev TS samples and the test/snippets.spec.ts sources for README + TSDoc snippets):

  • storage-blob/samples-dev/{snapshots,errorsAndResponses}.ts and the now-unused samples-dev/utils/stream.ts
  • storage-file-datalake/samples-dev/dataLakeServiceClient.ts
  • storage-file-share/samples-dev/shareServiceClient.ts
  • storage-*/test/snippets.spec.ts (drives README sections and src/Clients.ts TSDoc comments)

The samples/v12/{typescript,javascript} mirrors, READMEs, and TSDoc snippets in src/Clients.ts / src/clients.ts were regenerated via dev-tool samples publish and npm run update-snippets, which accounts for the bulk of the touched files.

Are there test cases added in this PR? (If not, why?)

No. This change only updates illustrative sample / documentation code; there is no runtime behavior change in any package. The internal streamToBuffer* helpers under src/utils/utils.ts (and their existing tests) are untouched.

Provide a list of related PRs (if any)

N/A

Command used to generate this PR:**(Applicable only to SDK release request PRs)

N/A

Checklists

  • Added impacted package name to the issue description
  • Does this PR needs any fixes in the SDK Generator?** (If so, create an Issue in the Autorest/typescript repository and link it here)
  • Added a changelog (if necessary)

Replace the hand-rolled streamToBuffer/streamToString helpers in samples-dev and README/TSDoc snippets with the built-in �uffer() from `node:stream/consumers`, and mention 	ext() as a one-liner alternative. The generated samples/v12 mirrors are republished accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the Storage Storage Service (Queues, Blobs, Files) label Jun 5, 2026
@jeremymeng jeremymeng mentioned this pull request Jun 5, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Storage Storage Service (Queues, Blobs, Files)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant